//连接数据库
const mongodb = require('mongoose')

mongodb.connect(
  'mongodb://localhost:27017/bigdata',
  { useNewUrlParser: true, useUnifiedTopology: true },
  function (err, db) {
    if (!err) {
      console.log('mongodb连接成功....')
    } else {
      console.log(err)
    }
  },
)
var Schema = mongodb.Schema //创建一个Schema模型骨架，并且设置好user模版
//bilibili用户信息
var BzUserSchema = new Schema({
  mid: { type: String } /*uuid*/,
  name: { type: String } /*昵称*/,
  face: { type: String } /*头像*/,
  level: { type: String } /*等级*/,
  label: { type: String } /*身份*/,
})
//bilibili主页视频
var BzVideoSchema = new Schema({
  aid: { type: Number } /*aid*/,
  cid: { type: Number } /*cid*/,
  bvid: { type: String } /*bvid*/,
  tname: { type: String } /*类型*/,
  pic: { type: String } /*图片*/,
  title: { type: String } /*标题*/,
  desc: { type: String } /*描述*/,
  duration: { type: Number } /*时长*/,
  owner: {
    mid: { type: String }, //up主mid
    name: { type: String }, //up主昵称
    face: { type: String }, //up主头像
  } /*up主*/,
  like: { type: Number } /*赞*/,
  dislike: { type: Number } /*踩*/,
  view: { type: Number } /*播放量*/,
  share: { type: Number } /*分享*/,
  favorite: { type: Number } /*收藏*/,
  coin: { type: Number } /*投币*/,
})
var twinkleNoteSchema = new Schema({
  name: { type: String }, //up主昵称
  mid: { type: String }, //up主mid
  face: { type: String }, //up主头像
  note: { type: String }, //评论
  noteTime: { type: String }, //评论时间
})
var BzUser = mongodb.model('BzUser', BzUserSchema)
var BzVideo = mongodb.model('BzVideo', BzVideoSchema)
var twinkleNote = mongodb.model('twinkleNote', twinkleNoteSchema)

module.exports = { BzUser, BzVideo, twinkleNote }
